home *** CD-ROM | disk | FTP | other *** search
- /*
- FileList 1.4
- "Search.c"
- */
-
- #include "FileSearch.h"
- #include "Main.h"
- #include "Stack.h"
- #include "Utilities.h"
- #include "Window.h"
- #include "Search.h"
-
- #define DeleteDialog 134 /* Delete? */
- #define DeleteOk 1
- #define DeleteNo 2
-
- #define RenameDialog 135 /* Rename volume */
- #define RenameOk 1
- #define RenameNo 2
- #define RenameRepl 3 /* Replace */
- #define RenameOld 4 /* Old volume name */
- #define RenameNew 5 /* New volume name */
-
- #define FindDialogF 136 /* Find (file) */
- #define FindDialogV 137 /* Find (volume) */
- #define FindOk 1
- #define FindNo 2
- #define FindStr 3 /* String to find */
- #define FindEqual 4 /* Exactly equal */
- #define FindBegin 5 /* Match beginning */
- #define FindInclude 6 /* Match somewhere */
- #define FindEnd 7 /* Match end */
- #define FindType 8 /* File type */
- #define FindCreator 9 /* File creator */
-
- #define NOTHING 0xFFFFFFFF
-
- /* ----- Dispose memory blocks ----------------------------------------- */
-
- void DisposeMemory (void)
- {
- FileData.max = VolumeData.max = InfoMax = 0;
- if (InfoBase)
- DisposPtr(InfoBase);
- }
-
- /* ----- Allocate memory blocks ---------------------------------------- */
-
- short NewMemory (
- unsigned long program, /* Minimum memory needed by program */
- unsigned short files, /* Percentage of files expected */
- unsigned short volumes, /* Percentage of volumes expected */
- unsigned short record) /* Average name size */
- {
- register long x, y;
- long grow;
-
- Heap = program;
- Record = record;
- record += sizeof(FileInfo) + 1;
- record *= 100;
- VolumeData.percent = volumes;
- FileData.percent = files;
- x = MaxMem(&grow); /* Compact heap, purge everything */
- x -= program; /* Memory available for data storage */
- if (x <= 0 || !(InfoBase = NewPtr(x)))
- goto err;
- y = (volumes + files) * sizeof(long) + record;
- VolumeData.max = (volumes * x)/y;
- FileData.max = (files * x)/y;
- if ((VolumeData.base =
- (long *)InfoBase + x/sizeof(long) - VolumeData.max)
- <= (long *)InfoBase)
- goto err;
- if ((FileData.base = VolumeData.base - FileData.max)
- <= (long *)InfoBase)
- goto err;
- InfoMax = (Ptr)FileData.base - InfoBase;
- return 0;
- err:
- DisposeMemory();
- return 1;
- }
-
- /* ----- Convert short to unsigned long -------------------------------- */
-
- static unsigned long int2long (register unsigned short x)
- {
- return (unsigned long)x;
- }
-
- /* ----- Return record address ----------------------------------------- */
-
- FileInfoPtr Address (
- register WindowDataPtr w,
- register long i)
- {
- return (FileInfoPtr)(InfoBase + ((w->base)[i] & 0x7FFFFFFF));
- }
-
- /* ----- Select record ------------------------------------------------- */
-
- void Select (
- register WindowDataPtr w,
- register long i,
- register Boolean sel)
- {
- w->select = sel ? i : NOTHING;
- }
-
- /* ----- Toggle record selection --------------------------------------- */
-
- void Toggle (
- register WindowDataPtr w,
- register long i)
- {
- Select(w, i, w->select == NOTHING);
- }
-
- /* ----- Check if record is selected ----------------------------------- */
-
- Boolean Selected (
- register WindowDataPtr w,
- register long i)
- {
- return w->select == i;
- }
-
- /* ----- Return volume name -------------------------------------------- */
-
- Byte *GetVolume (register FileInfoPtr p)
- {
- p = (FileInfoPtr)(InfoBase + p->volume);
- return (Byte *)(&p->name);
- }
-
- /* ----- Find path ----------------------------------------------------- */
-
- void InitPath (
- register FileInfoPtr p,
- register STACK *stack)
- {
- register short i;
-
- InitStack(stack);
- while (p->kind != VOLUME && PushStack(stack, p->parent))
- p = (FileInfoPtr)(InfoBase + p->parent);
- }
-
- Byte *NextPath (register STACK *stack)
- {
- register FileInfoPtr p;
- register unsigned long x;
-
- if ((x = PopStack(stack)) == STACKERROR)
- return 0;
- p = (FileInfoPtr)(InfoBase + x);
- return (Byte *)(&p->name);
- }
-
- /* ----- Accept new file record ---------------------------------------- */
-
- static short NewFile (unsigned long adr)
- {
- if (FileData.count >= FileData.max)
- return 1;
- (FileData.base)[FileData.count] = adr;
- FileData.count++;
- return 0;
- }
-
- /* ----- Accept new volume record -------------------------------------- */
-
- static short NewVolume (unsigned long adr)
- {
- if (VolumeData.count >= VolumeData.max)
- return 1;
- (VolumeData.base)[VolumeData.count] = adr;
- VolumeData.count++;
- return 0;
- }
-
- /* ----- Return length of info record ---------------------------------- */
-
- static unsigned long Length (register FileInfoPtr p)
- {
- register unsigned long length;
-
- length = sizeof(FileInfo) + p->name[0] + 1;
- if (length & 1)
- ++length; /* Make it even */
- return length;
- }
-
- /* ----- Return next info record --------------------------------------- */
-
- static FileInfoPtr NextRecord (register FileInfoPtr record)
- {
- return (FileInfoPtr)((Ptr)record + Length(record));
- }
-
- /* ----- Accept new info record ---------------------------------------- */
-
- static long NewInfo (
- short kind,
- unsigned long parent,
- unsigned long volume,
- Ptr name,
- unsigned long size,
- unsigned long cdate,
- unsigned long mdate,
- unsigned long x,
- unsigned long y)
- {
- register FileInfoPtr p;
- register unsigned long length;
- register unsigned long adr;
- register unsigned short namelength;
-
- namelength = name[0];
- if (namelength >= sizeof(FILENAME))
- namelength = sizeof(FILENAME) - 1;
- length = sizeof(FileInfo) + namelength + 1;
- if (length & 1)
- ++length; /* Make it even */
- if (InfoSize + length > InfoMax)
- return NOTHING;
- p = (FileInfoPtr)(InfoBase + InfoSize);
- p->kind = kind;
- p->parent = parent;
- p->volume = volume;
- p->size = size;
- p->cdate = cdate;
- p->mdate = mdate;
- p->type = x;
- p->creator = y;
- p->name[0] = namelength;
- BlockMove(name + 1, p->name + 1, namelength);
- adr = InfoSize;
- InfoSize += length;
- ++InfoCount;
- return adr;
- }
-
- /* ----- Find volume by name ------------------------------------------- */
-
- Boolean FindVolume (
- register Byte *name,
- unsigned long *index)
- {
- register unsigned long v;
- register FileInfoPtr p;
-
- for (v = 0; v < VolumeData.count; v++) {
- p = Address(&VolumeData, v);
- if (StrCompare(name, p->name) == 0) {
- *index = v;
- return TRUE;
- }
- }
- return FALSE;
- }
-
- /* ----- Unmount/eject volume ------------------------------------------ */
-
- void KillVolume (register HVolumeParam *VolPB)
- {
- register short vol, drive, err;
-
- /* Do not eject system volume or application volume */
- if (!(vol = VolPB->ioVRefNum) || vol == SysVol || vol == ApplVol)
- return;
- drive = VolPB->ioVDrvInfo; /* Drive number */
-
- FillMemory((Byte *)VolPB, sizeof(HVolumeParam), 0);
- VolPB->ioVRefNum = vol;
- err = PBUnmountVol(VolPB);
-
- FillMemory((Byte *)VolPB, sizeof(HVolumeParam), 0);
- VolPB->ioVRefNum = drive;
- err = PBEject(VolPB);
-
- /*
- if (err)
- Message(ERR_DISK, err);
- */
- }
-
- /* ----- Clear index tables -------------------------------------------- */
-
- static void ClearIndexTables (void)
- {
- register Ptr p, q, himem;
-
- FileData.count = VolumeData.count = 0;
- p = q = InfoBase;
- himem = p + InfoSize;
- while(q < himem) {
- switch (((FileInfoPtr)q)->kind) {
- case VOLUME:
- NewVolume(q - p);
- break;
- case FILE:
- NewFile(q - p);
- break;
- }
- q += Length((FileInfoPtr)q);
- }
- }
-
- /* ----- No sort ------------------------------------------------------- */
-
- void NoSort (void)
- {
- if (FileData.select != -1L)
- Select(&FileData, FileData.select, FALSE);
- if (VolumeData.select != -1L)
- Select(&VolumeData, VolumeData.select, FALSE);
- ClearIndexTables();
- Update();
- ClearSorted(&FileData);
- ClearSorted(&VolumeData);
- Dirty = TRUE;
- }
-
- /* ----- Rename a volume ----------------------------------------------- */
-
- static void AdjustInfoRecords (
- register FileInfoPtr p, /* First record to adjust */
- register Ptr max, /* Record limit */
- register long x, /* Highest valid index */
- register long offset) /* Reference offset */
- {
- while ((Ptr)p < max) {
- if (p->kind != VOLUME) {
- if (p->parent > x)
- p->parent += offset;
- if (p->volume > x)
- p->volume += offset;
- }
- p = NextRecord(p);
- }
- }
-
- #ifdef ADJUSTINDEX
- static void AdjustIndexTable (
- register long *base, /* Index table base */
- register long *max, /* Index table limit */
- register long x, /* Highest valid index */
- register long offset) /* Reference offset */
- {
- while (base < max) {
- if (*base > x)
- *base += offset;
- ++base;
- }
- }
- #endif
-
- static short NewVolumeName (
- register FileInfoPtr volume, /* Volume to rename */
- Byte *newname) /* New volume name */
- {
- register FileInfoPtr record;
- register long delta, x;
-
- /* Record length difference */
-
- delta = sizeof(FileInfo) + newname[0] + 1;
- if (delta & 1)
- ++delta; /* Make it even */
- delta -= Length(volume);
- if ((InfoSize + delta) > InfoMax)
- return 1; /* Error */
-
- /* Move all higher records then copy the new name */
-
- record = NextRecord(volume);
- if (delta && (x = InfoBase + InfoSize - (Ptr)record))
- BlockMove((Ptr)record, (Ptr)record + delta, x);
- BlockMove(newname, volume->name, *newname + 1);
- InfoSize += delta;
-
- /* Ajust all parent and volume references in info records
- and in index tables. */
-
- if (delta) {
- x = (Ptr)volume - InfoBase;
- AdjustInfoRecords(NextRecord(volume), InfoBase + InfoSize,
- x, delta);
- #ifdef ADJUSTINDEX
- AdjustIndexTable(VolumeData.base, VolumeData.base +
- VolumeData.count, x, delta);
- AdjustIndexTable(FileData.base, FileData.base + FileData.count,
- x, delta);
- #else
- ClearIndexTables();
- #endif
- }
-
- return 0; /* Ok */
- }
-
- /* ----- Clear selections ---------------------------------------------- */
-
- static void ClearSelection (register WindowDataPtr w)
- {
- if (w->select != NOTHING) {
- SetPort(w);
- ToggleIt(w, w->select);
- }
- }
-
- static void ClearSelections (void)
- {
- ClearSelection(&FileData);
- ClearSelection(&VolumeData);
- }
-
- /* ----- Select volume dialog ------------------------------------------ */
-
- void AddVolumes (void)
- {
- register HVolumeParam *VolPB;
- register short err;
- register short i, n, v;
- register DialogPtr dialog;
- short volumes[SelectCount];
- short check[SelectCount];
- Boolean eject;
- short item;
- Byte s[256];
-
- CenterDialog('DLOG', SelectDialog);
- if (!(dialog = GetNewDialog(SelectDialog, 0, -1)))
- return;
- SetWatch();
- FileSearchOpen(0);
- FirstVol(0);
- for (i = 0; i < SelectCount; i++) {
- VolPB = NextVol();
- if (VolPB->ioResult)
- break;
- volumes[i] = VolPB->ioVRefNum;
- check[i] = FALSE;
- /*
- NumToString((long)(VolPB->ioVRefNum), s);
- if (VolPB->ioVRefNum == SysVol)
- Append(s, "\p/SYS");
- if (VolPB->ioVRefNum == ApplVol)
- Append(s, "\p/APP");
- Append(s, "\p/");
- Append(s, VolPB->ioNamePtr);
- ControlName(dialog, i+SelectVolume, s);
- */
- ControlName(dialog, i+SelectVolume, VolPB->ioNamePtr);
- }
- n = i;
- FileSearchClose();
- for (i = n; i < SelectCount; i++) {
- volumes[i] = 0;
- check[i] = FALSE;
- ControlName(dialog, i+SelectVolume, EmptyStr);
- }
- eject = 0;
- ShowWindow(dialog);
- InitCursor();
- while (TRUE) {
- ModalDialog(0L, &item);
- if (item < SelectVolume)
- break;
- ControlToggle(dialog, item);
- }
- if (item == SelectOk) {
- for (i = 0; i < n; ++i)
- check[i] = ControlCheck(dialog, i + SelectVolume);
- eject = ControlCheck(dialog, SelectEject);
- }
- DisposDialog(dialog);
- if (item == SelectOk) {
- for (i = v = 0; i < n; i++)
- if (check[i]) {
- v++;
- if (err = SearchVol(volumes[i], eject)) {
- Message(err, 0);
- break;
- }
- }
- if (v) {
- Update();
- ClearSorted(&FileData);
- ClearSorted(&VolumeData);
- Dirty = TRUE;
- }
- }
- InitCursor();
- return;
- }
-
- /* ----- Delete a volume ----------------------------------------------- */
-
- static void CutVolume (long v)
- {
- register FileInfoPtr q, himem, x, p;
- register long lost;
-
- SetWatch();
- ClearSelections();
-
- p = q = Address(&VolumeData, v);
- himem = (FileInfoPtr)(InfoBase + InfoSize);
- do {
- --InfoCount;
- q = NextRecord(q);
- } while(q < himem && q->kind != VOLUME);
- lost = (Ptr)q - (Ptr)p;
- if (q < himem) {
- x = q;
- do {
- if (x->kind != VOLUME) {
- x->parent -= lost;
- x->volume -= lost;
- }
- x = NextRecord(x);
- } while(x < himem);
- BlockMove(q, p, (Ptr)himem - (Ptr)q);
- }
- InfoSize -= lost;
- ClearIndexTables();
-
- Dirty = (InfoSize) ? TRUE : FALSE;
- Update();
- ClearSorted(&FileData);
- ClearSorted(&VolumeData);
- InitCursor();
- }
-
- /* ----- Delete selected volume ---------------------------------------- */
-
- void DeleteVolume (void)
- {
- register FileInfoPtr p;
- register long x = VolumeData.select;
-
- if (x == NOTHING)
- return;
- p = Address(&VolumeData, x);
- ParamText(p->name, EmptyStr, EmptyStr, EmptyStr);
- CenterDialog('ALRT', DeleteDialog);
- if (CautionAlert(DeleteDialog, 0) != DeleteOk)
- return;
- CutVolume(x);
- }
-
- /* ----- Rename volume dialog ------------------------------------------ */
-
- static short RenameVol (
- register Byte *oldname,
- register Byte *name,
- Boolean replace)
- {
- register DialogPtr dialog;
- register Boolean cont = TRUE;
- register short result = 1;
- short item;
- unsigned long index;
-
- CenterDialog('DLOG', RenameDialog);
- if (!(dialog = GetNewDialog(RenameDialog, 0, -1)))
- return result;
- ShowHideControl(dialog, RenameRepl, replace);
- setText(dialog, RenameOld, oldname);
- setText(dialog, RenameNew, oldname);
- SelIText(dialog, RenameNew, 0, 0x7FFF);
- do {
- ModalDialog(0, &item);
- switch(item) {
- case RenameOk:
- getText(dialog, RenameNew, name);
- /* Make sure name is not too long and is unique */
- if (*name > (sizeof(VOLNAME) - 1) ||
- FindVolume(name, &index)) {
- SysBeep(1);
- break;
- }
- result = 0;
- /* Fall thru */
- case RenameNo:
- cont = FALSE;
- break;
- case RenameRepl:
- if (FindVolume(oldname, &index))
- CutVolume(index);
- result = 0;
- cont = FALSE;
- break;
- }
- } while(cont);
- DisposDialog(dialog);
- return result;
- }
-
- /* ----- Rename selected volume ---------------------------------------- */
-
- void RenameVolume (void)
- {
- register FileInfoPtr p;
- register long x = VolumeData.select;
- register Byte name[256];
-
- if (x == NOTHING)
- return;
- p = Address(&VolumeData, x);
- if (RenameVol(p->name, name, FALSE))
- return;
- ClearSelections();
- NewVolumeName(p, name);
- Dirty = TRUE;
- Update();
- ClearSorted(&FileData);
- ClearSorted(&VolumeData);
- }
-
- /* ----- Search all files on volume ------------------------------------ */
-
- #define AccessDenied -5000 /* If cataloging a file server volume */
-
- short SearchVol (short drive, Boolean eject)
- {
- register HVolumeParam *VolPB;
- register CInfoPBPtr FilePB;
- register err;
- register unsigned long dir, fil, vol;
- unsigned long index;
- STACK stack;
- short archive = 0;
- char name[256];
- unsigned long files = 0; /* Files on volume */
-
- FileSearchOpen(0); /* Initialize file search */
- err = ERR_DISK;
- InitStack(&stack);
- VolPB = FirstVol(drive);
- if (VolPB->ioResult)
- goto done2;
- *name = 0;
- /* If volume name exists, try to rename the new volume,
- or replace the old volume. */
- if (FindVolume(VolPB->ioNamePtr, &index) &&
- RenameVol((Byte *)VolPB->ioNamePtr, (Byte *)name, TRUE))
- goto done0;
- SetWatch();
- err = ERR_MEMORY;
- fil = VolPB->ioVAlBlkSiz;
- if ((dir = NewInfo(
- VOLUME, /* Kind */
- NOTHING, /* Parent pointer */
- NOTHING, /* Volume pointer */
- *name ? name : (Ptr)VolPB->ioNamePtr, /* Name */
- int2long(VolPB->ioVNmAlBlks) * fil, /* Total size */
- VolPB->ioVCrDate, /* Creation date */
- VolPB->ioVLsMod, /* Modification date */
- int2long(VolPB->ioVFrBlk) * fil, /* Free space */
- VolPB->ioVFilCnt)) == NOTHING) /* Files */
- goto done1;
- if (NewVolume(dir))
- goto done1;
- vol = dir;
- FirstFile(0); /* Initialize search thru all files */
- while (TRUE) {
- if (archive) { /* Reading from archive? */
- FilePB = NextArchiveFile();
- if (FilePB->hFileInfo.ioResult == eofErr) { /* End of archive */
- CloseArchive();
- archive = 0;
- if ((dir = PopStack(&stack)) == STACKERROR)
- goto done1;
- continue;
- }
- if (FilePB->hFileInfo.ioResult == fnfErr) { /* End of folder */
- if ((dir = PopStack(&stack)) == STACKERROR)
- goto done1;
- continue;
- } else {
- if (FilePB->hFileInfo.ioResult) {
- err = ERR_DISK;
- goto done1;
- }
- }
- } else { /* Not reading from archive */
- FilePB = NextFile();
- if (FilePB->hFileInfo.ioResult == fnfErr ||
- FilePB->hFileInfo.ioResult == dirNFErr) /* not found */
- if (PopDir()) { /* Pop up a level */
- if ((dir = PopStack(&stack)) == STACKERROR)
- goto done1;
- continue;
- } else /* ...if any */
- break; /* Normal loop exit */
- else {
- if (FilePB->hFileInfo.ioResult == AccessDenied)
- continue;
- if (FilePB->hFileInfo.ioResult) {
- err = ERR_DISK;
- goto done1;
- }
- }
- }
- if (FilePB->hFileInfo.ioFlAttrib & 0x10) { /* Directory */
- if ((fil = NewInfo(
- FOLDER, /* Kind */
- dir, /* Parent pointer */
- vol, /* Volume pointer */
- (Ptr)FilePB->dirInfo.ioNamePtr, /* Name */
- 0,
- FilePB->dirInfo.ioDrCrDat, /* Creation date */
- FilePB->dirInfo.ioDrMdDat, /* Modification date */
- 0,
- (long)FilePB->dirInfo.ioDrNmFls)) == NOTHING)
- goto done1;
- if (!PushStack(&stack, dir))
- goto done1;
- dir = fil;
- if (!archive)
- FirstFile(FilePB->dirInfo.ioDrDirID);
- } else { /* File */
- if (!archive &&
- (archive = IsArchive(&FilePB->hFileInfo))) {
- if ((fil = NewInfo(
- FOLDER, /* Kind */
- dir, /* Parent pointer */
- vol, /* Volume pointer */
- (Ptr)FilePB->dirInfo.ioNamePtr, /* Name */
- 0,
- FilePB->dirInfo.ioDrCrDat, /* Creation date */
- FilePB->dirInfo.ioDrMdDat, /* Modification date */
- 0,
- (long)FilePB->dirInfo.ioDrNmFls)) == NOTHING)
- goto done1;
- if (!PushStack(&stack, dir))
- goto done1;
- dir = fil;
- } else {
- if ((fil = NewInfo(
- FILE, /* Kind */
- dir, /* Parent */
- vol, /* Volume ptr */
- (Ptr)FilePB->hFileInfo.ioNamePtr, /* Name */
- FilePB->hFileInfo.ioFlLgLen +
- FilePB->hFileInfo.ioFlRLgLen, /* Size */
- FilePB->hFileInfo.ioFlCrDat, /* Creation date */
- FilePB->hFileInfo.ioFlMdDat, /* Modif. date */
- FilePB->hFileInfo.ioFlFndrInfo.fdType,
- FilePB->hFileInfo.ioFlFndrInfo.fdCreator))
- == NOTHING)
- goto done1;
- ++files; /* One more file in volume */
- if (NewFile(fil))
- goto done1;
- }
- }
- }
- /* Set correct file count */
- ((FileInfoPtr)(InfoBase + vol))->creator = files;
- done0:
- err = 0;
- done1:
- if (archive)
- CloseArchive();
- if (eject)
- KillVolume(VolPB);
- done2:
- FileSearchClose();
- InitCursor();
- return err;
- }
-
- /* ----- Find again ---------------------------------------------------- */
-
- void Again (void)
- {
- register WindowDataPtr w = (WindowDataPtr)FrontWindow();
- register unsigned long v;
- register unsigned long x;
- register FileInfoPtr p;
- register short y1, y2;
- Rect r;
-
- SetWatch();
- SetPort(w);
- ToggleIt(w, x = w->select);
- for (v = x + 1; v < w->count; v++) {
- p = Address(w, v);
- if ((!w->find[0] || (*w->match)(w->find, p->name)) &&
- (!w->type || (w->type == p->type)) &&
- (!w->creator || (w->creator == p->creator))) {
- y1 = GetCtlValue(w->vs);
- ContentRect((WindowPtr)w, &r);
- y2 = y1 + (r.bottom - r.top)/w->height;
- if (v < y1 || v >= y2) {
- SetCtlValue(w->vs, v - (y2 - y1)/2);
- InvalRect(&r);
- }
- ToggleIt(w, v);
- goto done;
- }
- }
- SysBeep(1); /* Nothing found */
- done:
- InitCursor();
- }
-
- /* ----- Find dialog --------------------------------------------------- */
-
- static void L2S (unsigned long x, register Byte *s)
- {
- *s++ = sizeof(unsigned long);
- BlockMove(&x, s, sizeof(unsigned long));
- printable(s, sizeof(unsigned long));
- }
-
- static unsigned long S2L (Byte *s)
- {
- unsigned long x = ' ';
-
- BlockMove(s + 1, &x, *s);
- return x;
- }
-
- typedef Boolean (*MP)();
-
- void Find (void)
- {
- register WindowDataPtr w = (WindowDataPtr)FrontWindow();
- register DialogPtr dialog;
- register Boolean cont = TRUE;
- register Byte name[256];
- register short i;
- register Byte s[256];
- unsigned long type, creator;
- Boolean ff;
- short item;
- static MP m[] = { StrEquals, StrBegins, StrIncludes, StrEnds };
- unsigned long x;
-
- SetPort(w);
- ToggleIt(w, x = w->select);
- if (w == &FileData) {
- ff = TRUE;
- i = FindDialogF;
- } else {
- ff = FALSE;
- i = FindDialogV;
- }
- CenterDialog('DLOG', i);
- if (!(dialog = GetNewDialog(i, 0L, -1L)))
- return;
- setText(dialog, FindStr, w->find);
- SelIText(dialog, FindStr, 0, 0x7FFF);
- if (ff) {
- if (w->type)
- L2S(w->type, s);
- else
- *s = 0;
- setText(dialog, FindType, s);
- if (w->creator)
- L2S(w->creator, s);
- else
- *s = 0;
- setText(dialog, FindCreator, s);
- }
- for (i = 0; i < 4; ++i)
- if (m[i] == w->match) {
- SetRadioButton(dialog, FindEqual, FindEnd, FindEqual + i);
- break;
- }
- do {
- ModalDialog(0L, &item);
- switch(item) {
- case FindOk:
- getText(dialog, FindStr, name);
- if (*name > (sizeof(w->find) - 1)) {
- SysBeep(1);
- break;
- }
- if (ff) {
- getText(dialog, FindType, s);
- if (*s > sizeof(unsigned long)) {
- SysBeep(1);
- break;
- }
- type = *s ? S2L(s) : 0;
- getText(dialog, FindCreator, s);
- if (*s > sizeof(unsigned long)) {
- SysBeep(1);
- break;
- }
- creator = *s ? S2L(s) : 0;
- }
- i = GetRadioButton(dialog, FindEqual, FindEnd) - FindEqual;
- case FindNo:
- cont = FALSE;
- break;
- case FindEqual:
- case FindBegin:
- case FindInclude:
- case FindEnd:
- SetRadioButton(dialog, FindEqual, FindEnd, item);
- break;
- }
- } while(cont);
- DisposDialog(dialog);
- SetPort(w);
- ToggleIt(w, x);
- if (item == FindOk) {
- BlockMove(name, w->find, *name + 1);
- if (ff) {
- w->type = type;
- w->creator = creator;
- }
- w->match = m[i];
- Again();
- }
- }
-